<?php

abstract class App_Abstract {

	/**
	 * @var array
	 */
	private static $_instances = array();
	
	protected $_tpl;
	
	/**
	 * @var Config
	 */
	public $config;
	
	/**
	 * @var Db
	 */
	protected $_db;

	/**
	 * @param string $configFile 
	 */
	private function __construct ($configFile) {
		$this->config = Config::fromFile($configFile);
	}

	/**
	 *
	 * @param string $configFile
	 * @param string $className
	 * @return App_Abstract
	 */
	public static function create ($configFile, $className = __CLASS__) {
		self::$_instances[$className] = new $className($configFile);
		return self::$_instances[$className];
	}

	/**
	 * @param string $className
	 * @return App_Abstract 
	 */
	public static function inst ($className = __CLASS__) {
		return $className == "App" && isset(self::$_instances['Admin']) ? self::$_instances['Admin'] : self::$_instances[$className];
	}
	
	/**
	 * @return Db
	 */
	public function db(){
		if(!$this->_db) $this->_db = new Db();
		return $this->_db;
	}

	abstract public function run ();

	/**
	 * @return Tpl
	 */
	abstract public function tpl();
	
}